#ifndef f_lib_vc10_mutex_h_
#define f_lib_vc10_mutex_h_

#include "../Common/cTypes.h"

class Mutex
{
public:
	Mutex();
	virtual ~Mutex();

	bool Lock();
	bool Unlock();

private:

#ifdef WIN32
	CRITICAL_SECTION m_cs;
#endif
	int m_nLockCount;

};

_inline Mutex::Mutex():
	m_nLockCount(0)
{
#ifdef WIN32
	::InitializeCriticalSection(&m_cs);
#endif
}

_inline Mutex::~Mutex()
{
	while(m_nLockCount > 0)
		Unlock();

#ifdef WIN32
	::DeleteCriticalSection(&m_cs);
#endif
}

_inline bool Mutex::Lock()
{
	++m_nLockCount;
#ifdef WIN32
	::EnterCriticalSection(&m_cs);
#endif
	return true;
}

_inline bool Mutex::Unlock()
{
	--m_nLockCount;
#ifdef WIN32
	::LeaveCriticalSection(&m_cs);
#endif
	return true;
}


#endif